package com.spring.boot.util;

public enum SexEnum {

	male(0, "男"), female(1, "女");
	private int index;
	private String sex;

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	SexEnum() {

	}

	SexEnum(int index, String sex) {
		this.index = index;
		this.sex = sex;
	}

	/**
	 * 根据性别获取下标
	 * 
	 * @param s
	 * @return
	 * @author YHQ
	 * @date 2015-12-30 下午3:33:04
	 */
	public static int getIndexBySex(String s) {
		for (SexEnum sex : SexEnum.values()) {
			if (sex.getSex().equals(s)) {
				return sex.getIndex();
			}
		}
		return 0;
	}

	/**
	 * 根据下标获取性别
	 * 
	 * @param s
	 * @return
	 * @author YHQ
	 * @date 2015-12-30 下午3:33:04
	 */
	public static String getSexByIndex(int index) {
		for (SexEnum sex : SexEnum.values()) {
			if (sex.getIndex() == index) {
				return sex.getSex();
			}
		}
		return "男";
	}

}
